home *** CD-ROM | disk | FTP | other *** search
- // Copyright (C) 1997-2002 Alias|Wavefront,
- // a division of Silicon Graphics Limited.
- //
- // The information in this file is provided for the exclusive use of the
- // licensees of Alias|Wavefront. Such users have the right to use, modify,
- // and incorporate this code into other products for purposes authorized
- // by the Alias|Wavefront license agreement, without fee.
- //
- // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- // PERFORMANCE OF THIS SOFTWARE.
- //
- ////////////////////////////////////////////////////////////////////////////////
- //
- // Procedure Name:
- // RNdeleteUnused
- //
- // Description:
- // Delete unused reference nodes.
- //
- // Input Arguments:
- // None.
- //
- // Return Value:
- // None.
- //
-
- proc string[] getUsedReferenceNodes(string $sceneFile)
- //
- // Description:
- // Returns all of the reference nodes used by a scene and its
- // references.
- //
- {
- int $index = 0;
- string $referenceNodes[];
-
- string $referenceFiles[];
- if (size($sceneFile) == 0) {
- // Get all of the references from the top-level scene.
- //
- $referenceFiles = `file -q -r`;
- } else {
- $referenceFiles = `file -q -r $sceneFile`;
- }
-
- int $i;
- int $nRefs = `size($referenceFiles)`;
- for ($i = 0; $i < $nRefs; $i++) {
- // Skip the untitled scene case.
- //
- if (size($referenceFiles[$i]) == 0) {
- continue;
- }
-
- string $rn = `file -q -rfn $referenceFiles[$i]`;
- if (size($rn) > 0) {
- $referenceNodes[$index++] = $rn;
- }
-
- string $rnList[] = getUsedReferenceNodes($referenceFiles[$i]);
- int $j;
- int $nChildren = size($rnList);
- for ($j = 0; $j < $nChildren; $j++) {
- $referenceNodes[$index++] = $rnList[$j];
- }
- }
-
- return $referenceNodes;
- }
-
- proc deleteReferenceNode(string $refNode)
- //
- // Description:
- // Delete the reference node if there are no connections made to it.
- //
- {
- string $connectionList[] = `listConnections $refNode`;
- int $numConnections = `size($connectionList)`;
- if ($numConnections == 0) {
- string $cmd = ("delete " + $refNode);
- evalEcho ($cmd);
- }
- }
-
- global proc RNdeleteUnused()
- //
- // Description:
- // Deletes unused reference nodes.
- //
- {
- string $rnList[] = `ls -type reference`;
- int $nRefs = size($rnList);
- if ($nRefs == 0) {
- // There are no reference nodes to delete.
- //
- return;
- }
-
- // Get all of the reference nodes associated with a scene.
- //
- string $rnUsedList[] = getUsedReferenceNodes("");
-
- int $i;
- for ($i = 0; $i < $nRefs; $i++) {
- if (!size(`ls -ro $rnList[$i]`)) {
- // This may be an unused reference node.
- //
- int $found = false;
- for ($nextRef in $rnUsedList) {
- if ($nextRef == $rnList[$i]) {
- $found = true;
- break;
- }
- }
-
- if ($found) {
- // This reference node is being used, so it should not be
- // deleted.
- //
- continue;
- }
-
- // Delete the reference node.
- //
- deleteReferenceNode($rnList[$i]);
- }
- }
- }
-